package ribbitmq_3;

import com.rabbitmq.client.*;

import java.io.IOException;
import java.util.Scanner;
import java.util.concurrent.TimeoutException;

public class producer_3 {
    public static void main(String[] args) throws IOException, TimeoutException {
        ConnectionFactory c = new ConnectionFactory();
        c.setHost("192.168.64.140");
        c.setPort(5672);
        c.setUsername("admin");
        c.setPassword("admin");

        Channel ch = c.newConnection().createChannel();
        //方式二 ch.exchangeDeclare("logs", "fanout")
        ch.exchangeDeclare("logs", BuiltinExchangeType.FANOUT);

        //定义循环发送消息
        while (true){
            System.out.println("请输入消息");
            String msg = new Scanner(System.in).nextLine();

            ch.basicPublish("logs",//交换机名
                    "",    //陆游建
                    null,      //其他属性消息持久化 MessageProperties.PERSISTENT_TEXT_PLAIN
                    msg.getBytes()); //转换字节

            System.out.println("发生成功");
        }
    }
}
